package com.moli.iov.third.invocation.op.base;

import com.google.common.collect.Maps;
import com.moli.iov.third.config.OpProperties;
import com.moli.iov.util.HttpUtil;
import java.io.IOException;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p>
 *
 * </p>
 *
 * @author zql
 * @since 2019/10/14 17:48
 */
@Slf4j
@Component
public class OpBaseHandler {

  @Autowired
  private TokenHandler tokenHandler;

  @Autowired
  private OpProperties opProperties;

  /**
   *
   * @param url
   * @param body
   * @throws IOException
   */
  public String post(String url, String body) throws IOException {

    String token = tokenHandler.getToken();

    return post(url, body, token);
  }

  /**
   * 访问OP
   * @param url
   * @param body
   * @param token
   * @return
   * @throws IOException
   */
  public String post(String url, String body, String token) throws IOException {

    Map<String, String> headers = Maps.newHashMap();
    headers.put("token", token);

    return HttpUtil.postJson(url, body, headers);
  }
}
